using System;
using System.Runtime.InteropServices;

namespace Triton.Common
{
	public static class OSInfo
	{
		private struct Struct92
		{
			public int int_0;

			public readonly int int_1;

			public readonly int int_2;

			public readonly int int_3;

			public readonly int int_4;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
			public readonly string string_0;

			public readonly short short_0;

			public readonly short short_1;

			public readonly short short_2;

			public readonly byte byte_0;

			public readonly byte byte_1;
		}

		private static string string_0;

		private static string string_1;

		private const int int_0 = 0;

		private const int int_1 = 1;

		private const int int_2 = 2;

		private const int int_3 = 3;

		private const int int_4 = 4;

		private const int int_5 = 5;

		private const int int_6 = 6;

		private const int int_7 = 7;

		private const int int_8 = 8;

		private const int int_9 = 9;

		private const int int_10 = 10;

		private const int int_11 = 11;

		private const int int_12 = 12;

		private const int int_13 = 13;

		private const int int_14 = 14;

		private const int int_15 = 15;

		private const int int_16 = 16;

		private const int int_17 = 17;

		private const int int_18 = 18;

		private const int int_19 = 19;

		private const int int_20 = 20;

		private const int int_21 = 21;

		private const int int_22 = 22;

		private const int int_23 = 23;

		private const int int_24 = 24;

		private const int int_25 = 25;

		private const int int_26 = 26;

		private const int int_27 = 27;

		private const int int_28 = 28;

		private const int int_29 = 29;

		private const int int_30 = 30;

		private const int int_31 = 31;

		private const int int_32 = 32;

		private const int int_33 = 35;

		private const int int_34 = 36;

		private const int int_35 = 38;

		private const int int_36 = 40;

		private const int int_37 = 41;

		private const int int_38 = 42;

		private const int int_39 = 101;

		private const int int_40 = 98;

		private const int int_41 = 99;

		private const int int_42 = 100;

		private const int int_43 = 48;

		private const int int_44 = 1;

		private const int int_45 = 2;

		private const int int_46 = 3;

		private const int int_47 = 1;

		private const int int_48 = 2;

		private const int int_49 = 16;

		private const int int_50 = 128;

		private const int int_51 = 256;

		private const int int_52 = 512;

		private const int int_53 = 1024;

		public static int Bits
		{
			get
			{
				if (Environment.Is64BitOperatingSystem)
				{
					return 64;
				}
				return 32;
			}
		}

		public static string Edition
		{
			get
			{
				if (string_0 != null)
				{
					return string_0;
				}
				string result = string.Empty;
				OperatingSystem oSVersion = Environment.OSVersion;
				Struct92 struct92_ = default(Struct92);
				struct92_.int_0 = Marshal.SizeOf(typeof(Struct92));
				if (GetVersionEx(ref struct92_))
				{
					int major = oSVersion.Version.Major;
					int minor = oSVersion.Version.Minor;
					byte byte_ = struct92_.byte_0;
					short short_ = struct92_.short_2;
					switch (major)
					{
					case 4:
						switch (byte_)
						{
						case 1:
							result = "Workstation";
							break;
						case 3:
							result = (((short_ & 2) == 0) ? "Standard Server" : "Enterprise Server");
							break;
						}
						break;
					case 5:
						switch (byte_)
						{
						case 1:
							result = (((short_ & 0x200) == 0) ? "Professional" : "Home");
							break;
						case 3:
							result = ((minor != 0) ? (((short_ & 0x80) == 0) ? (((short_ & 2) == 0) ? (((short_ & 0x400) == 0) ? "Standard" : "Web Edition") : "Enterprise") : "Datacenter") : (((short_ & 0x80) == 0) ? (((short_ & 2) == 0) ? "Server" : "Advanced Server") : "Datacenter Server"));
							break;
						}
						break;
					case 6:
					{
						if (GetProductInfo(major, minor, struct92_.short_0, struct92_.short_1, out var int_))
						{
							switch (int_)
							{
							case 0:
								result = "Unknown product";
								break;
							case 1:
								result = "Ultimate";
								break;
							case 2:
								result = "Home Basic";
								break;
							case 3:
								result = "Home Premium";
								break;
							case 4:
								result = "Enterprise";
								break;
							case 5:
								result = "Home Basic N";
								break;
							case 6:
								result = "Business";
								break;
							case 7:
								result = "Standard Server";
								break;
							case 8:
								result = "Datacenter Server";
								break;
							case 9:
								result = "Windows Small Business Server";
								break;
							case 10:
								result = "Enterprise Server";
								break;
							case 11:
								result = "Starter";
								break;
							case 12:
								result = "Datacenter Server (core installation)";
								break;
							case 13:
								result = "Standard Server (core installation)";
								break;
							case 14:
								result = "Enterprise Server (core installation)";
								break;
							case 15:
								result = "Enterprise Server for Itanium-based Systems";
								break;
							case 16:
								result = "Business N";
								break;
							case 17:
								result = "Web Server";
								break;
							case 18:
								result = "HPC Edition";
								break;
							case 20:
								result = "Express Storage Server";
								break;
							case 21:
								result = "Standard Storage Server";
								break;
							case 22:
								result = "Workgroup Storage Server";
								break;
							case 23:
								result = "Enterprise Storage Server";
								break;
							case 24:
								result = "Windows Essential Server Solutions";
								break;
							case 26:
								result = "Home Premium N";
								break;
							case 27:
								result = "Enterprise N";
								break;
							case 28:
								result = "Ultimate N";
								break;
							case 29:
								result = "Web Server (core installation)";
								break;
							case 30:
								result = "Windows Essential Business Management Server";
								break;
							case 31:
								result = "Windows Essential Business Security Server";
								break;
							case 32:
								result = "Windows Essential Business Messaging Server";
								break;
							case 35:
								result = "Windows Essential Server Solutions without Hyper-V";
								break;
							case 36:
								result = "Standard Server without Hyper-V";
								break;
							case 38:
								result = "Enterprise Server without Hyper-V";
								break;
							case 40:
								result = "Standard Server without Hyper-V (core installation)";
								break;
							case 41:
								result = "Enterprise Server without Hyper-V (core installation)";
								break;
							case 42:
								result = "Microsoft Hyper-V Server";
								break;
							case 48:
								result = "Professional";
								break;
							}
						}
						break;
					}
					}
				}
				string_0 = result;
				return result;
			}
		}

		public static string Name
		{
			get
			{
				if (string_1 != null)
				{
					return string_1;
				}
				string result = "unknown";
				OperatingSystem oSVersion = Environment.OSVersion;
				Struct92 struct92_ = default(Struct92);
				struct92_.int_0 = Marshal.SizeOf(typeof(Struct92));
				if (GetVersionEx(ref struct92_))
				{
					int major = oSVersion.Version.Major;
					int minor = oSVersion.Version.Minor;
					switch (oSVersion.Platform)
					{
					case PlatformID.Win32NT:
					{
						byte byte_ = struct92_.byte_0;
						switch (major)
						{
						case 3:
							result = "Windows NT 3.51";
							break;
						case 4:
							switch (byte_)
							{
							case 3:
								result = "Windows NT 4.0 Server";
								break;
							case 1:
								result = "Windows NT 4.0";
								break;
							}
							break;
						case 5:
							switch (minor)
							{
							case 0:
								result = "Windows 2000";
								break;
							case 1:
								result = "Windows XP";
								break;
							case 2:
								result = ((byte_ != 1) ? "Windows Server 2003" : "Windows XP");
								break;
							}
							break;
						case 6:
							switch (minor)
							{
							case 0:
								switch (byte_)
								{
								case 3:
									result = "Windows Server 2008";
									break;
								case 1:
									result = "Windows Vista";
									break;
								}
								break;
							case 1:
								switch (byte_)
								{
								case 3:
									result = "Windows Server 2008 R2";
									break;
								case 1:
									result = "Windows 7";
									break;
								}
								break;
							case 2:
								switch (byte_)
								{
								case 2:
									result = "Windows Server 2012 R2";
									break;
								case 1:
									result = "Windows 8";
									break;
								}
								break;
							}
							break;
						}
						break;
					}
					case PlatformID.Win32Windows:
						if (major == 4)
						{
							string text = struct92_.string_0;
							switch (minor)
							{
							case 90:
								result = "Windows Me";
								break;
							case 10:
								result = ((!(text == "A")) ? "Windows 98" : "Windows 98 Second Edition");
								break;
							case 0:
								result = ((text == "B" || text == "C") ? "Windows 95 OSR2" : "Windows 95");
								break;
							}
						}
						break;
					}
				}
				string_1 = result;
				return result;
			}
		}

		public static string ServicePack
		{
			get
			{
				string empty = string.Empty;
				Struct92 struct92_ = default(Struct92);
				struct92_.int_0 = Marshal.SizeOf(typeof(Struct92));
				if (GetVersionEx(ref struct92_))
				{
					empty = struct92_.string_0;
				}
				return empty;
			}
		}

		public static int BuildVersion => Environment.OSVersion.Version.Build;

		public static string VersionString => Environment.OSVersion.Version.ToString();

		public static Version Version => Environment.OSVersion.Version;

		public static int MajorVersion => Environment.OSVersion.Version.Major;

		public static int MinorVersion => Environment.OSVersion.Version.Minor;

		public static int RevisionVersion => Environment.OSVersion.Version.Revision;

		[DllImport("Kernel32.dll")]
		internal static extern bool GetProductInfo(int int_54, int int_55, int int_56, int int_57, out int int_58);

		[DllImport("kernel32.dll")]
		private static extern bool GetVersionEx(ref Struct92 struct92_0);
	}
}
